package chap05.iterator;

/**
 * Created by root on 2017/7/11.
 */
public class InterIterApp2 {
    public static void main(String[] args){
        LinkList theList = new LinkList();
        ListIterator iter1 = theList.getItearator();

        iter1.insertAfter(21);
        iter1.insertAfter(18);
        iter1.insertAfter(30);
        iter1.insertAfter(7);
        iter1.insertAfter(24);
        iter1.insertAfter(45);

        theList.displayList();

        iter1.reset();
        while (!iter1.atEnd()) {
            Link aLink = iter1.getCurrent();
            if (aLink.dData % 3 == 0) {
                iter1.deleteCurrent();
            } else {
                iter1.nextLink();
            }
        }
        if (iter1.atEnd()){
            Link aLink = iter1.getCurrent();
            if (aLink.dData % 3 ==0) {
                iter1.deleteCurrent();
            }
        }
        theList.displayList();
    }
}
